package com.storage.joyce.storageapp;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.storage.joyce.storageapp.util.CommonJSONParser;
import com.storage.joyce.storageapp.util.HttpService;
import com.storage.joyce.storageapp.util.JsonToMap;
import com.storage.joyce.storageapp.util.Tools;
import com.storage.joyce.storageapp.util.view.LoadingDialog;

import org.kymjs.kjframe.http.HttpCallBack;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends Activity {
    Button button;
    private Dialog dialog;
    private TextView tv1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = (Button) findViewById(R.id.button);
        tv1 = (TextView) findViewById(R.id.tv1);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog = LoadingDialog.createLoadingDialog(MainActivity.this);
                dialog.show();

                //login请求参数
                Map<String, Object> login_map = new HashMap<>();
                login_map.put("storeKey", "111111");
                login_map.put("uquip", 0);
                login_map.put("imei", android.os.Build.SERIAL);
                login_map.put("system", android.os.Build.VERSION.RELEASE);
                login_map.put("os", 1);

                HttpService.post(HttpService.login_url, login_map, new HttpCallBack() {
                    @Override
                    public void onSuccess(Map<String, String> headers, byte[] t) {
                        super.onSuccess(headers, t);
                        //Map<String, Object> map = CommonJSONParser.parse(new String(t));
                        Map<String,Object> map = JsonToMap.toMap(new String(t));
                        Tools.loge("登陆成功返回日志：" + map);
                        Log.e("dsds",map+"");
                        tv1.setText("登陆成功返回日志：" + map);
                    }

                    @Override
                    public void onFailure(int errorNo, String strMsg) {
                        super.onFailure(errorNo, strMsg);
                        dialog.dismiss();
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                        dialog.dismiss();

                    }
                });
            }
        });

    }




}
